<?php

// $Id$

require_once($WSC->get_site_inc_dir().'modules/tangra_cms/pages/ci/base/ci_type_preview_wp.class.php');
require_once($WSC->get_site_inc_dir().'modules/tangra_cms/classes/ci/ci_types/tcms_ci_normal_ci_dbc.class.php');


class CI_Normal_CI_Preview_WP extends CI_Type_Preview_WP {
	public function create_view($name = 'default') {
		$ret = new TCMS_Admin_Page_View($this, $name, 'modules/tangra_cms/pages/_ci/');

		return $ret;
	}


	protected function ci_event($ci_normal_ci_id) {
		$dbc = $this->get_dbc();

		$ci_normal_ci = new TCMS_CI_normal_ci_DBC();
		if ($ci_normal_ci->load_by_id($dbc, $ci_normal_ci_id)) {
			$ci_normal_ci_prep = $this->prepare_normal_ci($ci_normal_ci);
			$this->export('ci_normal_ci', $ci_normal_ci_prep);

			$ci_id = $ci_normal_ci->get_ci()->get_id();
			$this->export('ci_id', $ci_id);

			$this->export_attachments($dbc, $ci_id);
			$this->export_images($dbc, $ci_id);

			$view = $this->get_view('default');
		} else {
			$view = $this->get_view('not_exist');
		}

		return $view;
	}


	private function prepare_normal_ci(TCMS_CI_normal_ci_DBC $ci_normal_ci) {
		$ret['id'] = $ci_normal_ci->get_ci()->get_id();
		$ret['content'] = $ci_normal_ci->get_content()->get_value();
		$ret['created'] = $ci_normal_ci->get_ci()->get_created();

		return $ret;
	}
}